﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
using Mclib;

namespace MclibTester
{
	public partial class FormMain : Form
	{
		/// <summary>
		/// Constructs a new form.
		/// </summary>
		public FormMain()
		{
			InitializeComponent();

			this.Test3();
		}
		public FormMain(int iTest)
		{
			InitializeComponent();
			if(iTest==1)
				this.Test1();
			else if(iTest==2)
				this.Test2();
			else if(iTest==3)
				this.Test3();
		}
		/// <summary>
		/// Tests the functions Gaussian.InvCdf() and Histogram() simultaneously in the Pb control.
		/// Tests the ShortString() function in the Rtb control.
		/// </summary>
		public void Test1()
		{
			int i;
			int nRand = 20000;
			double[] u = new double[nRand];
			double[] z = new double[nRand];
			Gaussian G = new Gaussian();
			//	Generate randon uniform numbers.
			for (i=0; i<nRand; i++)
			{
				u[i] = Util.Random.NextDouble();
				z[i] = G.InvCdf(u[i]);
			}
			//	Create a histogram
			Histogram h = new Histogram(-4.0, 4.0, 300);
			h.RegisterSamples(z);
			int maxBin;
			int totalBinned;
			h.Summarize(true, out totalBinned, out maxBin);
			double[] densHist = h.Density(true, maxBin);
			double[] densReal = new double[densHist.Length];
			double[] densCdf = new double[densHist.Length];
			for (i=0; i<densReal.Length; i++)
			{
				densCdf[i] = G.Cdf(h.Centers[i]);
				densReal[i] = G.Pdf(h.Centers[i]) / G.PdfScalar;
				Rtb.AppendText(h.Centers[i].ToString() + ", " + densCdf[i].ToString() + ", " + densReal[i].ToString() + ", " + densHist[i].ToString() +"\n");
			}
			Rtb.AppendText("===================\n");
			for (i=0; i<1000; i++)
				Rtb.AppendText((((double)i+0.5)/1000.0).ToString() +", "+ G.InvCdf(((double)i+0.5)/1000.0).ToString() + "\n");
			Rtb.AppendText("===================\n");
			//	Create a data series from the histogram.
			DataSeries ds = new DataSeries(h.Centers, densHist);
			ds.Pen = new Pen(Color.Red, 2.0f);
			//	Create an axis and add the data series.
			Axis ax = new Axis();
			ax.DataRect = new RectangleF(-4.0f, 0.0f, 8.0f, 1.0f);
			ax.DataTickX = new float[] { -4.0f, -3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f };
			//ax.DataTickY = new float[] { 0.0f,0.25f,0.5f,0.75f,1.0f };
			ax.DataTickY = new float[] { 0.0f,0.125f,0.25f,0.375f,0.5f,0.625f,0.75f,0.875f,1.0f };
			ax.Children.Add(ds);
			//	Create the Gaussian PDF
			ds = new DataSeries(h.Centers, densReal);
			ds.Pen = new Pen(Color.Blue, 2.5f);
			ax.Children.Add(ds);
			//	Create the Gaussian CDF
			ds = new DataSeries(h.Centers, densCdf);
			ds.Pen = new Pen(Color.Green, 3.0f);
			ax.Children.Add(ds);
			//	Add the axis to this controls list of axes.
			Axes.Add(ax);
			//	Invalidate painting area
			Pb.Invalidate();

			//	Test the ShortString function
			NiceNumberMaker nice = new NiceNumberMaker();
			double n;
			n = +0.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = -1.0*100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.0*10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.0*1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.0*100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.0*10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.0*1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = +1.0*1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.0*10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.0*100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.0*1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.0*10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.0*100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = -1.0/100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.0/10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.0/1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.0/100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.0/10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.0/1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = +1.0/1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.0/10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.0/100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.0/1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.0/10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.0/100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("===================\n");
			n = -1.000000001*100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.000000001*10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.000000001*1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.000000001*100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.000000001*10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.000000001*1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = +1.000000001*1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.000000001*10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.000000001*100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.000000001*1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.000000001*10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.000000001*100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = -1.000000001/100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.000000001/10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.000000001/1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.000000001/100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.000000001/10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.000000001/1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = +1.000000001/1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.000000001/10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.000000001/100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.000000001/1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.000000001/10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.000000001/100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("===================\n");
			n = -0.999999999*100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -0.999999999*10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -0.999999999*1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -0.999999999*100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -0.999999999*10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -0.999999999*1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = +0.999999999*1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +0.999999999*10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +0.999999999*100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +0.999999999*1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +0.999999999*10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +0.999999999*100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = -0.999999999/100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -0.999999999/10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -0.999999999/1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -0.999999999/100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -0.999999999/10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -0.999999999/1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = +0.999999999/1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +0.999999999/10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +0.999999999/100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +0.999999999/1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +0.999999999/10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +0.999999999/100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("===================\n");
			n = -1.05*100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.05*10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.05*1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.05*100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.05*10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.05*1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = +1.05*1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.05*10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.05*100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.05*1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.05*10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.05*100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = -1.05/100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.05/10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.05/1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.05/100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.05/10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = -1.05/1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("------------------\n");
			n = +1.05/1.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.05/10.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.05/100.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.05/1000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.05/10000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			n = +1.05/100000.0; Rtb.AppendText(n.ToString() + " = " + nice.ShortString(n) + '\n');
			Rtb.AppendText("===================\n");
		}
		/// <summary>
		/// Test Histogram2, DataSurface, IsoContours
		/// </summary>
		public void Test2()
		{
			int i;

			//--------------------------------
			//	Generate randon uniform numbers.
			//--------------------------------
			int nRand = 40000;
			double[,] u = new double[nRand,2];
			double[,] z = new double[nRand,2];
			Gaussian G = new Gaussian();
			for (i=0; i<nRand; i++)
			{
				u[i,0] = Util.Random.NextDouble();
				u[i,1] = Util.Random.NextDouble();
				z[i,0] = G.InvCdf(u[i,0]);
				z[i,1] = G.InvCdf(u[i,1]);
			}
			//--------------------------------


			//--------------------------------
			//	Create a histogram
			//--------------------------------
			Histogram2 h = new Histogram2(-3.0,3.0,-3.0,3.0,200,200);
			h.RegisterSamples(z,0,1);
			//--------------------------------


			//--------------------------------
			//	Create an axis.
			//--------------------------------
			Axis ax = new Axis();
			//ax.DataRect = new RectangleF(-4.0f, -4.0f, 8.0f, 8.0f);
			//ax.DataTickX = new float[] { -4.0f, -3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f };
			//ax.DataTickY = new float[] { -4.0f, -3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f };
			ax.DataRect = new RectangleF(-3.0f, -3.0f, 6.0f, 6.0f);
			ax.DataTickX = new float[] { -3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f };
			ax.DataTickY = new float[] { -3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f };
			//--------------------------------


			//--------------------------------
			//	Create the data surface to display an image of the distribution
			//--------------------------------
			DataSurface ds = new DataSurface(h,true);
			ds.BlurLevel = Math.Pow(ds.BlurLevel,0.9);
			//ds.BlurLevel = 0.025; // 0.025
			ds.BkType = BlurKernelType.Gaussian;
			ds.Color = new double[] {0.0,0.0,1.0};
			ds.CalcBitmap();
			ax.Children.Add(ds);
			//--------------------------------


			//--------------------------------
			//	Create an IsoContours to display the iso-density contours.
			//--------------------------------
			//----inner
			IsoContours iso = new IsoContours(ds.Zblur,0.05);
			iso.Pen = new Pen(Color.FromArgb(80,80,255),1.0f);
			ax.Children.Add(iso);

			//iso = new IsoContours(ds.Zblur,0.30);
			//iso.Pen = new Pen(Color.FromArgb(40,40,255),1.0f);
			//ax.Children.Add(iso);

			/*
			//----inner
			iso = new IsoContours(ds.Zblur,0.85);
			iso.Pen = new Pen(Color.LightGray,1.0f);
			ax.Children.Add(iso);
			//----0.middle
			iso = new IsoContours(ds.Zblur,0.70);
			iso.Pen = new Pen(Color.Gray,1.0f);
			ax.Children.Add(iso);
			//----outer
			iso = new IsoContours(ds.Zblur,0.50);
			iso.Pen = new Pen(Color.DarkGray,1.0f);
			ax.Children.Add(iso);
			//----outer
			iso = new IsoContours(ds.Zblur,0.25);
			iso.Pen = new Pen(Color.DarkGray,1.0f);
			ax.Children.Add(iso);
			//--------------------------------
			*/

			//	Add the axis to this controls list of axes.
			Axes.Add(ax);
			//	Invalidate painting area
			Pb.Invalidate();
		}
		/// <summary>
		/// Test DataSurfaces
		/// </summary>
		public void Test3()
		{
			int i;

			//--------------------------------
			//	Generate randon uniform numbers.
			//--------------------------------
			int nRand = 40000;
			double[,] u = new double[nRand,6];
			double[,] z = new double[nRand,6];
			Gaussian G = new Gaussian();
			for (i=0; i<nRand; i++)
			{
				u[i,0] = Util.Random.NextDouble();
				u[i,1] = Util.Random.NextDouble();
				u[i,2] = Util.Random.NextDouble();
				u[i,3] = Util.Random.NextDouble();
				u[i,4] = Util.Random.NextDouble();
				u[i,5] = Util.Random.NextDouble();
				z[i,0] = G.InvCdf(u[i,0])-0.71;
				z[i,1] = G.InvCdf(u[i,1])-0.71;
				z[i,2] = G.InvCdf(u[i,2])-0.71;
				z[i,3] = G.InvCdf(u[i,3])+0.71;
				z[i,4] = G.InvCdf(u[i,2])+0.71;
				z[i,5] = G.InvCdf(u[i,3]);
			}
			//--------------------------------


			//--------------------------------
			//	Create a histogram
			//--------------------------------
			Histogram2[] h = new Histogram2[3];
			h[0] = new Histogram2(-4.0,4.0,-4.0,4.0,200,200);
			h[1] = new Histogram2(-4.0,4.0,-4.0,4.0,200,200);
			h[2] = new Histogram2(-4.0,4.0,-4.0,4.0,200,200);
			h[0].RegisterSamples(z,0,1);
			h[1].RegisterSamples(z,2,3);
			h[2].RegisterSamples(z,4,5);
			//--------------------------------


			//--------------------------------
			//	Create an axis.
			//--------------------------------
			Axis ax = new Axis();
			//ax.DataRect = new RectangleF(-4.0f, -4.0f, 8.0f, 8.0f);
			//ax.DataTickX = new float[] { -4.0f, -3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f };
			//ax.DataTickY = new float[] { -4.0f, -3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f };
			ax.DataRect = new RectangleF(-4.0f, -4.0f, 8.0f, 8.0f);
			ax.DataTickX = new float[] { -4.0f, -3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f };
			ax.DataTickY = new float[] { -4.0f, -3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f };
			//--------------------------------


			//--------------------------------
			//	Create the data surface to display an image of the distribution
			//--------------------------------
			DataSurfaces dss = new DataSurfaces(h,true);
			//dss.BlurLevel = Math.Pow(dss.BlurLevel,0.9);
			//dss.BlurLevel = 0.1; // 0.025
			dss.BkType = BlurKernelType.Gaussian;
			dss.CalcBitmap();
			ax.Children.Add(dss);
			//Bitmap bmp = dss.Bmp;
			//bmp.Save(Application.StartupPath + "/bmp.jpg");
			//Rtb.AppendText(Application.StartupPath);
			//--------------------------------

			//--------------------------------
			//	Create iso-contours
			//--------------------------------
			IsoContours iso;
			for(int iSurf=0; iSurf<dss.Z.Length; iSurf++)
			{
				iso = new IsoContours(dss.Surfaces[iSurf].Zblur,0.1);
				iso.Pen = new Pen(
					ColorMap.FromDouble(ColorMap.DesaturateAndLimit(dss.Surfaces[iSurf].Color, 0.25)),
					1.0f);
				ax.Children.Add(iso);
			}
			//--------------------------------
			

			//	Add the axis to this controls list of axes.
			Axes.Add(ax);
			//	Invalidate painting area
			Pb.Invalidate();
		}
		/// <summary>
		/// The axes to be painted in the Pb control.
		/// </summary>
		public List<Axis> Axes = new List<Axis>();
		/// <summary>
		/// Draw each axis onto the specified drawing surface.
		/// </summary>
		/// <param name="sender">A new painting info object based on the Pb control and the drawing rectangle (in Pb client coordinates).</param>
		/// <param name="e">The painting context and other event-related information.</param>
		public void DrawAxes(object sender, PaintEventArgs e)
		{
			for (int i=0; i<Axes.Count; i++)
				Axes[i].OnPaint(sender, e);
		}
		/// <summary>
		/// The event handler that draws the Pb control.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void Pb_Paint(object sender, PaintEventArgs e)
		{
			e.Graphics.FillRectangle(Brushes.White, Pb.ClientRectangle);
			DrawAxes(new PaintingInfo(Pb, new RectangleF(0.0f,0.0f,Pb.Width,Pb.Height)), e);
		}
		/// <summary>
		/// The Pb control is invalidated when it is resized
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void Pb_Resize(object sender, EventArgs e)
		{
			Pb.Invalidate();
		}
	}
}